package com.zhuanzhuan.hero.user.vo;

import com.zhuanzhuan.hero.user.dto.BasePageQueryDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName PageQueryResultWrapper
 * @Description
 * @Author hanjunjun
 * @Date 2024/1/4 15:41
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PageResultWrapper<T> extends BasePageQueryDTO {

    private long total;

    private List<T> records;

    private Boolean hasNext;

    public PageResultWrapper(long total, List<T> records, Boolean hasNext, BasePageQueryDTO baseQuery) {
        this.total = total;
        this.records = records;
        this.hasNext = hasNext;
        this.setPageNum(baseQuery.getPageNum());
        this.setPageSize(baseQuery.getPageSize());
    }

    public static <T> PageResultWrapper<T> empty(BasePageQueryDTO baseQuery){
        return new PageResultWrapper<>(0, new ArrayList<>(), false, baseQuery);
    }

    public static <T> PageResultWrapper<T> wrapper(long total, List<T> list, boolean hasNext, BasePageQueryDTO baseQuery){
        return new PageResultWrapper<>(total, list, hasNext, baseQuery);
    }
}
